﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MyToDo.Shared.Dtos;
using MyToDo.Shared.Parameters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WPFPrismAPI.Context;
using WPFPrismAPI.Service;

namespace WPFPrismAPI.Controllers
{
    /// <summary>
    /// 待办事项控制器
    /// </summary>
    [Route("api/[controller]/[action]")]//  api/路由的名字/具体方法的名字
    [ApiController]
    public class ToDoController : ControllerBase
    {
        private readonly IToDoService service;

        public ToDoController(IToDoService service)
        {
            this.service = service;
        }
        [HttpGet]
        public async Task<ApiResponse> Get(int id)
        {
            return await service.GetsingleAsync(id);
        }

        [HttpGet]
        public async Task<ApiResponse> GetAll([FromQuery] ToDoParameter param)
        {
            return await service.GetAllAsync(param);
        }

        [HttpGet]
        public async Task<ApiResponse> Summary()
        {
            return await service.Summary();
        }

        [HttpPost]
        public async Task<ApiResponse> Add([FromBody] ToDoDto model)
        {
            return await service.AddAsync(model);
        }

        [HttpPost]
        public async Task<ApiResponse> Update([FromBody] ToDoDto model)
        {
            return await service.UpdateAsync(model);
        }

        [HttpDelete]
        public async Task<ApiResponse> Delete(int id)
        {
            return await service.DeleteAsync(id);
        }
    }
}
